package com.gusti.turnos.model;

import java.util.GregorianCalendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.gusti.turnos.persistence.model.AbstractModelObject;

/**
 * 
 * @author gusti
 *
 */
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=12)
public abstract class Event extends AbstractModelObject {

	private static final long serialVersionUID = -5082933510848889351L;

	//PROPERTIES
	@ManyToOne
	@JoinColumn(name = "userId", nullable = false)
	@Basic(optional=false)
	private User owner;

	@ManyToOne
	@JoinColumn(name = "appointmentId", nullable = false)
	@Basic(optional=false)
	private Appointment appointment;

	private GregorianCalendar date;

	//MODIFIERS
	public User getOwner() {
		return owner;
	}
	public void setOwner(User owner) {
		this.owner = owner;
	}

	public Appointment getAppointment() {
		return appointment;
	}
	public void setAppointment(Appointment appointment) {
		this.appointment = appointment;
	}

	@Basic(optional=false)
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	public GregorianCalendar getDate() {
		return date;
	}
	public void setDate(GregorianCalendar date) {
		this.date = date;
	}

	//OTHERS
	@Transient
	public long getOwnerId() {
		if( this.owner != null ) {
			return this.owner.getId();
		}
		return -1;
	}
}
